home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / sun3.md / memPC.s,v < prev    next >
Encoding:
Text File  |  1989-02-10  |  3.2 KB  |  124 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @| @;
  7.  
  8.  
  9. 1.1
  10. date     89.02.10.11.52.34;  author brent;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Routine to grab the PC of the calling routine
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* 
  27.  * memPC.s --
  28.  *
  29.  *     Procedures for obtain the PC of the caller of a routine.
  30.  *
  31.  *  $Header: memPC.s,v 2.0 87/09/03 19:00:38 andrew Exp $ SPRITE (Berkeley)
  32.  *
  33.  * Copyright 1987 Regents of the University of California
  34.  * All rights reserved.
  35.  */
  36.  
  37.  
  38. #if    defined(VAX) || defined(vax) || defined(uvax)
  39.  
  40. /*
  41.  * The stack layout on a VAX when Mem_CallerPC is called. The calls instruction
  42.  * on the VAX updates the frame pointer, so we have to go back two levels
  43.  * on the stack to get the PC of the call to Mem_Alloc/Free.
  44.  *
  45.  *   Foo calls Mem_Alloc (or Mem_Free):
  46.  *
  47.  * Top of the stack (it grows down from here)
  48.  *    +----------------------------+
  49.  *    | ... (Foo's frame)          |
  50.  *    |----------------------------|
  51.  *    | Arg. to Mem_Alloc          |
  52.  *    |----------------------------|
  53.  *    | # of args to Mem_Alloc     |
  54.  *    |----------------------------|
  55.  * 16 | PC of "calls Mem_Alloc"    |    2) left in r0
  56.  *    |----------------------------|
  57.  * 12 | Foo's FP                   |
  58.  *    |----------------------------|
  59.  *  8 | Foo's AP                   |
  60.  *    |----------------------------|
  61.  *  4 | mask/PSW                   |
  62.  *    |----------------------------|
  63.  *  0 | condition handler          | :Mem_Alloc's FP
  64.  *    |----------------------------|
  65.  *    | local variables            |
  66.  *    |----------------------------|
  67.  * 16 | PC of "calls Mem_CallerPC" |
  68.  *    |----------------------------|
  69.  * 12 | Mem_Alloc's FP             |    1) copy to r0
  70.  *    |----------------------------|
  71.  *  8 | Mem_Alloc's AP             |
  72.  *    |----------------------------|
  73.  *  4 | mask/PSW                   |
  74.  *    |----------------------------|
  75.  *  0 | condition handler          | :Mem_CallerPC's FP
  76.  *    +----------------------------+
  77.  */
  78.  
  79.     .globl    _Mem_CallerPC
  80. _Mem_CallerPC:
  81.     .word 0
  82.     movl    12(fp),r0    /* 1) r0 = fp of caller */
  83.     movl    16(r0),r0    /* 2) r0 = pc with fp */
  84.     ret
  85.  
  86. #endif    defined(VAX) || defined(vax) || defined(uvax)
  87.  
  88.  
  89. #if    defined(mc68000) || defined(sun2) || defined(sun3)
  90. /*
  91.  * The stack layout on a MC680?? when Mem_CallerPC is called. The routine 
  92.  * doesn't use a link instruction so it is still using Mem_Alloc/Free's 
  93.  * frame pointer (reg. a6).
  94.  *
  95.  *   Foo calls Mem_Alloc (or Mem_Free):
  96.  *
  97.  * Top of the stack (it grows down from here)
  98.  *   +----------------------------+
  99.  *   | ....                       |
  100.  *   |----------------------------|
  101.  *   | Saved Foo's caller FP      |
  102.  *   |----------------------------|
  103.  *   | Saved registers, local var |
  104.  *   |----------------------------|
  105.  * 4 | PC of "jsr Mem_Alloc"      |
  106.  *   |----------------------------|
  107.  * 0 | Saved Foo's FP             | :A6 (Mem_Alloc's FP)
  108.  *   |----------------------------|
  109.  *   | Saved registers, local var |
  110.  *   |----------------------------|
  111.  *   | PC of "jsr Mem_CallerPC"   |
  112.  *   |----------------------------|
  113.  *   | ....                       | :SP
  114.  *   +----------------------------+
  115.  */
  116.  
  117.     .globl    _Mem_CallerPC
  118. _Mem_CallerPC:
  119.     movl    a6@@(4),d0    /* PC of the caller of Mem_Alloc. */
  120.     rts
  121.  
  122. #endif    defined(mc68000) || defined(sun2) || defined(sun3)
  123. @
  124.